//
// Created by Criinal Nicole on 2021/6/2.
//

#ifndef GFD_GFDCOMPARE_H
#define GFD_GFDCOMPARE_H

#include <vector>
#include "../dataStructure/GFD.h"
#include "../Discovering/SubGraphMatch.h"


bool GFDCompare(GFD &gfd1, GFD &gfd2, GFD &ansGFD) {
    if (gfd1._pattern.empty() ||
        gfd2._pattern.empty() ||
        gfd1._pattern.size() != gfd2._pattern.size())
        return false;
    if (gfd1._pattern.at(0).getLabel() != gfd1._pattern.at(0).getLabel())
        return false;
    for (int i = 0; i < gfd1._pattern.size(); ++i) {
        if (gfd1._pattern.at(i).getLabel() != gfd1._pattern.at(i).getLabel()) {
            return false;
        }
    }
    ansGFD._pattern = gfd1._pattern;
    for (auto &literal1:gfd1._literalPairVector) {
        for (auto &literal2:gfd2._literalPairVector) {
            bool match = true;
            for (auto &lit1:literal1.first) {
                for (auto &lit2:literal2.first) {
                    if (!(lit1 == lit2)) {
                        match = false;
                        break;
                    }
                }
                if (!match)break;
            }
            if (!match)continue;
            ansGFD._literalPairVector.push_back(literal1);
            break;
        }
    }


    return !ansGFD._literalPairVector.empty();
}

#endif //GFD_GFDCOMPARE_H
